<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="新增方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gainManner', validatorRules.gainManner]" :trigger-change="true" dictCode="gain_manner" placeholder="请选择新增方式"/>
        </a-form-item>
        <a-form-item label="辅料SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ancillarySn', validatorRules.ancillarySn]" placeholder="请输入辅料SN"></a-input>
        </a-form-item>
        <a-form-item label="批次数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['batchNum', validatorRules.batchNum]" placeholder="请输入批次数量"></a-input>
        </a-form-item>
        <a-form-item label="辅料料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ancillaryCode', validatorRules.ancillaryCode]" placeholder="请输入辅料料号"></a-input>
        </a-form-item>
        <a-form-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['supplier', validatorRules.supplier]" placeholder="请输入供应商"></a-input>
        </a-form-item>
        <a-form-item label="生产批号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['produceCode', validatorRules.produceCode]" placeholder="请输入生产批号"></a-input>
        </a-form-item>
        <a-form-item label="重量(克)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['weight', validatorRules.weight]" placeholder="请输入重量(克)"></a-input>
        </a-form-item>
        <a-form-item label="入库单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inputwareCode']" placeholder="请输入入库单号"></a-input>
        </a-form-item>
        <a-form-item label="RoHs标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['rohsToken']" :trigger-change="true" dictCode="yn" placeholder="请选择RoHs标志"/>
        </a-form-item>
        <a-form-item label="辅料类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ancillaryType']" placeholder="请输入辅料类型"></a-input>
        </a-form-item>
        <a-form-item label="辅料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ancillaryName']" placeholder="请输入辅料名称"></a-input>
        </a-form-item>
        <a-form-item label="辅料规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ancillaryGague']" placeholder="请输入辅料规格"></a-input>
        </a-form-item>
        <a-form-item label="保质期(天)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shelfLife']" placeholder="请输入保质期(天)"></a-input>
        </a-form-item>
        <a-form-item label="品质到期时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择品质到期时间" v-decorator="['dueDate']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="过炉时间(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['crossStovetime']" placeholder="请输入过炉时间(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="回温时长(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['heatTime']" placeholder="请输入回温时长(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="开罐保质期(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['openShelflife']" placeholder="请输入开罐保质期(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="回温次数上限" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['heatNumlimit']" placeholder="请输入回温次数上限"></a-input>
        </a-form-item>
        <a-form-item label="回温衰减(%)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['heatDecline']" placeholder="请输入回温衰减(%)"></a-input>
        </a-form-item>
        <a-form-item label="搅拌时间(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['stirTime']" placeholder="请输入搅拌时间(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择生产日期" v-decorator="['produceDate']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="回温上限时间(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['heatTimelimit']" placeholder="请输入回温上限时间(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="搅拌上限时间(分钟)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['stirTimelimit']" placeholder="请输入搅拌上限时间(分钟)"></a-input>
        </a-form-item>
        <a-form-item label="库位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wareSite']" placeholder="请输入库位"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['notes']" rows="4" placeholder="请输入备注"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"


  export default {
    name: "MesChiefdataAncillarytoolModal",
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          gainManner: {
            rules: [
              { required: true, message: '请输入新增方式!'},
            ]
          },
          ancillarySn: {
            rules: [
              { required: true, message: '请输入辅料SN!'},
            ]
          },
          batchNum: {
            rules: [
              { required: true, message: '请输入批次数量!'},
            ]
          },
          ancillaryCode: {
            rules: [
              { required: true, message: '请输入辅料料号!'},
            ]
          },
          supplier: {
            rules: [
              { required: true, message: '请输入供应商!'},
            ]
          },
          produceCode: {
            rules: [
              { required: true, message: '请输入生产批号!'},
            ]
          },
          weight: {
            rules: [
              { required: true, message: '请输入重量(克)!'},
            ]
          },
        },
        url: {
          add: "/chiefdata/mesChiefdataAncillarytool/add",
          edit: "/chiefdata/mesChiefdataAncillarytool/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'gainManner','ancillarySn','batchNum','ancillaryCode','supplier','produceCode','weight','inputwareCode','rohsToken','ancillaryType','ancillaryName','ancillaryGague','shelfLife','dueDate','crossStovetime','heatTime','openShelflife','heatNumlimit','heatDecline','stirTime','produceDate','heatTimelimit','stirTimelimit','wareSite','notes'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'gainManner','ancillarySn','batchNum','ancillaryCode','supplier','produceCode','weight','inputwareCode','rohsToken','ancillaryType','ancillaryName','ancillaryGague','shelfLife','dueDate','crossStovetime','heatTime','openShelflife','heatNumlimit','heatDecline','stirTime','produceDate','heatTimelimit','stirTimelimit','wareSite','notes'))
      },

      
    }
  }
</script>